﻿<Page
    x:Name="PageRoot"
    x:Class="Skrape.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Skrape"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton Icon="Home" Label="Home" Command="{Binding Source={StaticResource GlobalResources}, Path=GoHomeCommand}"/>
                <AppBarButton Icon="Copy" Label="Copy" Command="{Binding Source={StaticResource GlobalResources}, Path=CopyCommand}"/>
                <AppBarButton Icon="Paste" Label="Paste" Command="{Binding Source={StaticResource GlobalResources}, Path=PasteCommand}"/>
                <AppBarButton Icon="Download" Label="Download" Command="{Binding Source={StaticResource GlobalResources}, Path=DownloadCommand}"/>
            </CommandBar.PrimaryCommands>
            <CommandBar.SecondaryCommands>
                <AppBarButton Icon="Favorite" Label="Set" Command="{Binding Source={StaticResource GlobalResources}, Path=FavoriteCommand}"/>
                <AppBarButton Icon="Save" Label="Save" Command="{Binding Source={StaticResource GlobalResources}, Path=SaveCommand}"/>
                <AppBarButton Icon="Add" Label="Add" Command="{Binding Source={StaticResource GlobalResources}, Path=AddCommand}"/>
                <AppBarButton Icon="Refresh" Label="Refresh" Command="{Binding Source={StaticResource GlobalResources}, Path=RefreshCommand}"/>
                <AppBarButton Icon="Delete" Label="Delete" Command="{Binding Source={StaticResource GlobalResources}, Path=DeleteCommand}"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <CollectionViewSource x:Name="GroupedPages"
                                  Source="{Binding Source={StaticResource GlobalResources}, Path=DataManager.Groups}"
                                  IsSourceGrouped="True"
                                  ItemsPath="Pages">
            </CollectionViewSource>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <AppBarButton Click="ButtonBase_OnClick" Icon="Back"
                IsEnabled="{Binding Frame.CanGoBack, ElementName=PageRoot}"/>
        <TextBlock Grid.Column="1"
                   Grid.Row="0"
                   Text="Skrape for Windows 8.1 Preview" 
                   Style="{StaticResource HeaderTextBlockStyle}"
                   Margin="0 0 0 40"></TextBlock>
        <GridView Grid.Row="1"
                  Grid.Column="1"   
                  SelectionMode="Single"
                  IsItemClickEnabled="True"
                  ItemClick="OnItemClick"
                  ItemsSource="{Binding Source={StaticResource GroupedPages}}"
                  SelectedItem="{Binding Source={StaticResource GlobalResources}, Path=DataManager.CurrentPage}"
                  >
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid Width="250">
                        <Image Width="250" Height="250" Source="{Binding ThumbnailPath}"/>
                        <Rectangle Height="50" 
                                   Fill="Black"
                                   VerticalAlignment="Top"
                                   Opacity="0.7"></Rectangle>
                        <TextBlock Text="{Binding Title}"
                                   Height="50"
                                   VerticalAlignment="Top"
                                   Style="{StaticResource BaseTextBlockStyle}"
                                   Margin="6,0,0,0"
                                   TextTrimming="WordEllipsis"/>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,40,6">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"></RowDefinition>
                                </Grid.RowDefinitions>
                                <Button Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Title}" 
                                                   Margin="3,-7,10,10" 
                                                   Style="{StaticResource SubheaderTextBlockStyle}"/>
                                        <TextBlock Text="{StaticResource ChevronGlyph}" 
                                                   FontFamily="Segoe UI Symbol"
                                                   Margin="0,-7,10,10"
                                                   Style="{StaticResource SubheaderTextBlockStyle}"></TextBlock>
                                    </StackPanel>
                                </Button>
                                <TextBlock Text="{Binding Description}" 
                                           Grid.Row="1"
                                           Style="{StaticResource SubtitleTextBlockStyle}"
                                           Margin="3,-7,10,10"></TextBlock>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" 
                                                   Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>
        <Rectangle x:Name="Overlay"
                   Grid.Row="1"
                   Grid.Column="1"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Stretch"
                   Fill="Black"
                   Opacity="0.7"
                   Visibility="Collapsed"/>
        <ProgressBar x:Name="Progress"
                     Grid.Row="1"
                     Grid.Column="1"
                     Height="10"
                     HorizontalAlignment="Stretch"
                     IsIndeterminate="True"
                     IsEnabled="True"
                     Visibility="Collapsed"/>
        <Popup x:Name="AddPopup"
               Grid.Row="0"
               Grid.Column="0"
               Grid.RowSpan="2"
               Grid.ColumnSpan="2"
               IsLightDismissEnabled="True"
               HorizontalAlignment="Stretch"
               VerticalAlignment="Stretch"
               VerticalOffset="140">
            <StackPanel Orientation="Horizontal" 
                            Background="Black" 
                            Width="9999">
                <TextBlock Text="Enter the URL to Add:"
                           Style="{StaticResource SubtitleTextBlockStyle}"
                           Margin="60 6 6 6"/>
                <TextBox x:Name="NewUrl" 
                         Width="500" 
                         Grid.Column="1" 
                         Margin="12 6 6 6"/>
                <Button x:Name="AddButton"
                        Margin="12 6 6 6"
                        Content="Add URL"
                        Click="AddButton_OnClick"/>
            </StackPanel>
        </Popup>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="LoadingStates">
                <VisualState x:Name="LoadedState"/>
                <VisualState x:Name="LoadingState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Overlay"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
